package com.dayangxiaoen.pms.config;

import com.dayangxiaoen.pms.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author dayangxiaoen
 */
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        //跨域配置
//        registry.addMapping("/**").allowedOrigins("http://localhost:8080");
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截test 接口 后续遇到需要拦截的接口是 在配置真正的拦截接口
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/product/**")
                .addPathPatterns("/chart/**");
    }
}
